<?php

class CollectWwwilaoyoucn extends CollectBase
{
    public static function getPageContent($url) { 
            import("@.ORG.Utility");
			$pagehtml= Utility::DoGet($url);

            $pagehtml = preg_replace("/　/",'',$pagehtml);   
      
            //charset   
			$pageinfo[charset] = 'utf-8';
 
            //desctiption  
            preg_match('@<meta\s+name=\"*description\"*\s+content\s*=\s*([^/>]+)/*>@i',$pagehtml,$matches);  
 
            $desc = trim($matches[1]);  
            $pageinfo[description] = str_replace("\"", '',$desc);  
              
     
            preg_match('@<meta\s+name=\"*keywords\"*\s+content\s*=\s*([^/>]+)/*>@i',$pagehtml,$matches);  

            $keywords = trim($matches[1]);  
            $pageinfo[keywords] = str_replace("\"", '',$keywords);  
     
              
            preg_match("/<title>(.*)<\/title>/smUi",$pagehtml, $matches);  
            $pageinfo[title] = trim($matches[1]);  
              
            preg_match("/<body.*>(.*)<\/body>/smUi",$pagehtml, $matches);  


			//个性正则开始
			$pagetitle = $pageinfo['title'];
			$pagetitle = explode('-', $pagetitle);
			$pageinfo['title'] = trim($pagetitle[0]);
			
			preg_match("/<td\s[^<>]*id=\"postmessage_[0-9]*\"[^<>]*>(.*)<\/td>/Uisx",$pagehtml, $matches2);
						
			$message = self::replaceHtmlAndJs2($matches2[1]);
			
			preg_match_all("/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]|\[img=\d{1,4}[x|\,]\d{1,4}\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", $message, $image1, PREG_SET_ORDER);
			preg_match_all("/\<img.+src=('|\"|)?(.*)(\\1)([\s].*)?\>/ismUe", $message, $image2, PREG_SET_ORDER);			
		
			$temp = $imagereplace = array();
			if(is_array($image1) && !empty($image1)) {
				foreach($image1 as $value) {
					$temp[] = array(
						'0' => $value[0],
						'1' => trim(!empty($value[1]) ? $value[1] : $value[2])
					);
				}
			}
			if(is_array($image2) && !empty($image2)) {
				foreach($image2 as $value) {
					$temp[] = array(
						'0' => $value[0],
						'1' => trim($value[2])
					);
				}
			}	
			if(is_array($temp) && !empty($temp)) {
				foreach($temp as $value) {
					$imageurl = $value[1];
					if(strlen($imageurl) && !preg_match('#/http#',$imageurl)) {
						$imagereplace['oldimageurl'][] = $value[0];
						$imagereplace['newimageurl'][] = '[img]http://www.ilaoyou.cn/'.$imageurl.'[/img]';
					}
				}
				if($imagereplace){
				    $message = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $message);	
				}
			}
					
			$pageinfo['message'] = $message; 			
			              
            return $pageinfo;  
     
    }  

}
?>